package com.hongkzh.www.look.enterprise.userinfo.view.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hongkzh.www.R;
import com.hongkzh.www.look.enterprise.userinfo.model.bean.MediaPhotoBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 自媒体图集的Adpter
 * Created by as on 2018/3/30.
 */

public class MediaPhotoAdapter extends RecyclerView.Adapter<MediaPhotoAdapter.ViewHolder> implements View.OnClickListener {



    private  int page;
    private List<MediaPhotoBean.DataBean.ListBean> mList = new ArrayList<>();
    private MediaPhotoBean.DataBean data = new MediaPhotoBean.DataBean();

    public MediaPhotoAdapter(int page) {
        this.page = page;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.media_photo, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        Glide.with(holder.itemView).load(mList.get(position).getCoverPhoto()).into(holder.IVPhoto); //加载图片的封面
        holder.TvPhotoName.setText(mList.get(position).getName()); //显示图片的名字
        holder.TvXinNum.setText(mList.get(position).getViewCount()+""); //显示关注的个数
        holder.itemView.setOnClickListener(this);


    }


    public void add(MediaPhotoBean photoBean) {

//        int PageNum=photoBean.getData().getPageNumber();
//        Log.i("获取PageNum的值=======",PageNum+"");

        if (photoBean.getData().isFirstPage()) {
            mList = photoBean.getData().getList();
        } else {
            for (int i = 0; i < photoBean.getData().getList().size(); i++) {
                mList.add(photoBean.getData().getList().get(i));
            }
        }
    }


    public  void  ClearList(){
        if(mList!=null && mList.size()!=0 ){
            mList.clear();
        }
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }


    public interface OnItemClickListener {
        void onItemClick();
    }

    @Override
    public void onClick(View v) {
        onItemClickListener.onItemClick();
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }




    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.IV_photo)
        ImageView IVPhoto;
        @BindView(R.id.Tv_photoName)
        TextView TvPhotoName;
        @BindView(R.id.IV_xin_State)
        ImageView IVXinState;
        @BindView(R.id.Tv_xin_Num)
        TextView TvXinNum;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
